import { fetchChannelAPI, ChannelsItem } from '@/apis/list'
import { useEffect, useState } from 'react'

//抽象useTabs组件数据和方法
function useTabs() {
    //获取数据
    const [channels, setChannels] = useState<ChannelsItem[] | null>([])

    useEffect(() => {
        const getChannels = async () => {
            try {
                const res = await fetchChannelAPI()
                setChannels(res.data.data.channels)
            } catch (error) {
                throw new Error("this is msg error")
            }
        }
        getChannels() 
    }, [])

    return {
        channels,
        setChannels
    }
}

export { useTabs }